{Use Case Name}

authored by: {Author/s}

Duration: 90 mins

Level: Intermediate        Pre-requisite Skills:Python

Scenario

{Using User Story format, write a description of the problem you are trying to solve for this use case.}

What this Use Case will teach you

At the end of this use case you will:

{Introduction/Background or History relating to problem}

{Keep it concise. We're not after "War and Peace" but enough background information to inform the reader on the rationale for solving this problem or background non-technical information that helps explain the approach.}

{Sub-Section Title}

{Sub-Section blurb} {Use Links for references and be sure to acknowledge your sources and any attributions.}

  Which Melbourne Open Data should I use?

To begin we shall first import the necessary libraries to support our [exploratory data analysis|visualisation|predictive analytics|reporting] using Melbourne Open data.

The following are core packages required for this exercise:

To connect to the Melbourne Open Data Portal we must establish a connection using the sodapy library by specifying a domain, being the website domain where the data is hosted, and an application access token which can be requested from the City of Melbourne Open Data portal by registering here

For this exercise we will access the domain without an application token

Next, we will look at one specific dataset to better understand its structure and how we can use it.

Our data requirements from this use case include the following:

For this exercise, we shall start by examining the {Name of dataset}. Each dataset in the Melbourne Open Data Portal has a unique identifier which can be used to retrieve the dataset using the sodapy library.

The {Name of Dataset} dataset unique identifier is {unique identifier goes here}. We will pass this identifier into the sodapy command below to retrieve this data.

This dataset is placed in a Pandas dataframe and we will inspect the first three rows.

Example code from this point on from the New Business Location Use Case...

We can see that there are 10,402 records and 10 fields describing each record.

Each record show us the number of dwellings for each individual property and the type of dwelling e.g. House/Townhouse, Residential Apartments, etc.

The location of each property is given using:

The Census year that the data was collected is also shown.

For our analysis of this dataset and others we will be restricting our analysis to the 2020 CLUE Census and summarising the data to CLUE Block level.

Summarising Residential Dwelling data

We want to plot the density of both residential dwellings and employment at city block level rather than a specific property or address. We can use a choropleth map to do this.

Let's start by summarising the data at CLUE small area and Block level.

Note: We include CLUE Small Area as one of our group by fields so we can display the CLUE Small area name in the popup window when you hover over the area on the map.

We want to summarise the data by summing the number of dwellings across all rows in the same CLUE Block.

The following cell creates a dataframe containing this summary of residential dwellings.

Visualising Residential Dwelling on a Choropleth Map

We use the Plotly Python Open Source Graphing Library to generate maps from mapbox.

Creating a choropleth map requires us to know the geometry(shape) of each CLUE Block area as a collection of latitude and longitude points defining a polygon. This data can be downloaded from the Melbourne Open Data Portal in GeoJSON format.

We also need to supply the data to be used to highlight the CLUE Blocks and that data must include the same unique identifier for each Block contained in the GeoJSON data set.

Below we extract the Melbourne CLUE Block polygons into a JSON datatype.

The final line in the cell displays the unique key for each polygon which must also exist in the Residential Dwelling dataset.

Now using just one function call called 'choropleth_mapbox' we can diaplay an interactive map using the block GeoJSON data to define the regions and the dwellingsByBlock dataframe to define the summarised data by block.

You've successfully used Melbourne CLUE Open Data and Plotly to visualise residential density in the City of Melbourne!
Now zoom in and out on the map above to explore the city and areas of high and low residential density.

This is your first step to selecting a suitable location for your new business!

You can explore the Residential Density data here.

Visualising Residential Density and Cafe or Restaurant Seating

To build our view of cafe venue seating and how it relates to residential density we need to visualise both datasets on the same interactive map view.

We can do this by adding a new layer (or "trace" as it is called in Plotly) to our previous map of residential density.

Let's extract the Melbourne CLUE cafe, restaurant, bistro seats dataset and summarise it so its ready to plot.

Above we can see our summary dataframe has calculated the total number of seats (indoor and outdoor) at each unique locations (latitude and longitude).

Since there is such a wide variance in venue seating across the city we need to scale the size of the bubbles drawn on the map to just a few (16) distinct sizes.

We set the lowest scale to 3 to ensure even the smallest venue's bubble is large enough when one zooms in at block level.

The next step is to display both the Choropleth and Scatter maps. We first draw the choropleth map showing residential density. We then draw the scatter plot assigning it as a trace (aka "layer") to the existing figure then show both.

You've successfully used Melbourne CLUE Open Data and Plotly to visualise residential density and venue seating in the City of Melbourne in one map!
Now zoom in and out on the map above to explore the city and areas of high residential density but low venue seating.

This could be a possible location for your new business!

You can explore the Venue Seating data in more detail here.

Building an Interactive Visualisation for New Business Location

In the previous step we saw how we can create a new layer, also called a trace, to an existing mapbox plot in order to visualise both residential density and cafe or Restaurant venue seating on the one map.

We now wish to add Employment Density to this visualisation. Since Employment density and Residential density both require use a choropleth map to visualise data at CLUE block level, we canot overlay these two layers at the same time.

We therefore need a way to select the base choropleth map to show either residential density or employment density and then optionally turn on or off the venue seating as an additional scatter map box layer.

To achieve this interactivity we can make use of Plotly express functions to build a drop down menu and button to be overlaid on the map.

We will require three datasets and associated layers (traces) for this visualation.

Let's start by extracting our third dataset titled "Employment per industry for blocks 2020" and performing some data preparation prior to plotting.

Note: The **"Employment per industry for blocks 2020"** dataset is a summary of employment at CLUE Block level and so we do not need to perform a groupby aggregation on the dataset.

Now we have a dataset showing total number of employmees by CLUE block, let's visualise it as a choropleth map and overlay venue seating.

In this map visualisation we will use a different map style called "open-street-map" which lets us identify the names of venues close to where the venue seating measures have been reported. Note that not all venues may have been marked on Open Street Maps.

Mapbox styles which do not require a Mapbox API token are 'open-street-map', 'white-bg', 'carto-positron', 'carto-darkmatter', 'stamen- terrain', 'stamen-toner', 'stamen-watercolor'. Mapbox styles which do require a Mapbox API token are 'basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite- streets'.

Source: plotly.express.line_mapbox documentation

Combining all map layers into one interactive map box visualisation

Let's now build a single map box visualisation using our three datasets.

Our first step is to create a base plotly figure to which we can add each individual map plot as a new layer.

The title of the visualisation and any common parameters can be set using the fig.update_layout() method.

In the cell below we also have defined two custom colorscales, one continuous for the choropleth map and the other discrete for the scatter map plot.

We then create a figure for each dataset and add it as a layer to the base figure using the fig.add_trace() method.

Finally, we define buttons and text to appear along the top of the map.

Each button turns on a combination of layers when it is clicked. The layers it turns on are defined in the 'visible' arg array with the order of boolean values corresponding to the map layers in the order they were added.

For example: When the 'Residential Density & Seating' button is clicked it turns on the 1st and 3rd layer as defined by the following argument 'visible':[True, False, True] . The 1st layer was the Residential Dwelling density choropleth map and the 3rd layer was the Venue Seating Scatter map.

Congratulations. Our interactive map is now complete!

Now you can use the controls on the map above to explore the City of Melbourne and observe the residential density and employment density of each city block in relation to venue seating capacity.

If you would like to extend this interactive map further, please visit the City of Melbourne Open Data Site and explore some of the other valuable datasets including: